Part Number Hot Search : 
LV5803 74F832 SPB16090 LL19A DG411CJ LTC1153 LHI958 124U6R3
Product Description
Full Text Search
 

To Download AN1147 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  1/22 july 1999 ? 1. introduction in this application note is presented an efficient and flexible method to evaluate the value of a variable resistor in the range 1k w 10k w (i.e. it could be an ntc resistance for a thermal regulation control process). the level of accuracy that can be reached by using a timer integrated in the st52x301 micro and an external circuitry in addition to the microcontroller (mirror current circuit) is very high. the evaluation of the resistance is done through an indirect measurement related to the determination of the charge time (at constant current) of a capacitor included in the mirror current. the high stability together with the precision of this time interval measurement is strictly related to the features of the st52x301 on-chip timer. it is a timer fully programmable and configurable by the user so that it results easy and flexible to use and, at the same time, allows to reach very high resolution of the evaluated measure. the indirect methodology used in this application note is only an example of the various applications where the presence of a timer is required to determine the physical quantities involved in a control process algorithm. this script aims to show to the user a typical application of the timer and its powerful and easy management in fuzzystudio tm 3.0 environment. moreover, a serial communication between the micro and a pc architecture is developed by providing both the software program and the hardware interface necessary to implement the communication between the two systems. 2. the st52x301 timer peripheral st52x301 offers one on-chip timer peripheral consisting of an 8-bit counter with a 16-bit programmable prescaler, giving a maximum count of 2 24 , and control logic that allows the working configuration and the setting of the type of peripheral outputs. the content of the 8-bit counter can be read/written and is incremented on the rising edge of the 16-bit prescaler output. moreover, it can be read under program control at any instant of the counting phase and loaded into a variable. any value between 0 and ffffh can be assigned to the prescaler. in figure 1 is shown the dialog box of fuzzystudio tm 3.0 atimer configurationo with the settings that have been used in our application. a brief description of timer settings follows: n prescaler out period : the value of the prescaler out period in m s or in the corresponding decimal value (16 bits word); n ouput polarity : defines the polarity of the timer output signal (timerout); n timerout wave form : this is a signal with frequency equal to the working timer frequency divided by the starting value of the prescaler (16 bits) and counter (8 bits). the timer output can be either a square wave with duty-cycle 50% or a pulse signal (with pulse duration equal to the prescaler ouput signal period; see figure 3); n start/stop : the start/stop of the prescaler counting can be provided from an internal or external source. moreover the start/stop of the counting depends on either the level or the edge of a tstart signal. n counter loading from : selects the source of the counter value between a location of the register file and the fuzzy core; n clock source : selects the source of the working timer frequency; n interrupt signal : the timer can be programmed to generate an interrupt request until the end of the count or when there is a falling and/or rising edge in the timerout signal (see figure 3). AN1147 application note high resolution digital conversion of an ntc by st52x301 authors: a. cucuccio, g. rascona'
AN1147 - applicat ion note 2/22 in figures 2 and 3 the timer functionalities and the timing of timerout signal are shown respectively. for more details on the timer's functions, configuration and interrupts refer to st52x301 data sheet. fig. 1 - timer configuration fig. 2 - timer features
high resolution digital conversion of an ntc by st52x301 3/22 fig. 3 - st52x301 timerout signal type 3. general description let us suppose we want to measure the resistance value of a variable resistor (i.e. a trimmer) in the range from 1k up to 10k. any other range of values can be considered without any significant changes to be made on the methodology described later on. as stated in the introduction, our aim is to determine a resistance value by measuring a time interval related to it (in our case this relationship will be linear). the time interval is determined by using the programmable timer of st52x301 microcontroller whose key features have been already described previously. the main principle of the resistance-time conversion is based on determining the necessary time so that a capacitor, with initial voltage equal to zero, is charged up to a fixed voltage threshold value v th (threshold voltage of a schimitt's trigger making up the input stage of a generic input pin of the parallel port in the microcontroller) . thus, if the charging current of the capacitor is kept constant, the relationship that relates our quantities is: v th = i(r)/c t (1) where: n v th : is the threshold voltage. n i() : is the time-independent current depending on the resistance value. it allows the linear charging of the capacitor. this is accomplished by means of a mirror current circuit linked externally to the mi- cro; n r : is the current value of resistance that determines the corresponding time interval during which the capacitor is charged; n c : is the capacitance that allows to obtain the resistance-time conversion. its value is determined in order to have a certain time to gt the measure and also it depends from the current intensity flowing through the mirror current. in our case we have chosen a 33 m f capacitor; n t : is the time needed for the capacitor voltage to vary from 0v up to the threshold voltage value (about 1.9v). we can observe that is just the constant current charging that allows to obtain a very linear relationship between the resistance value and the relative time interval determining a measure of it. as the current flowing in the capacitor is inversely proportional to resistance, the following relationships are valid: i(r) = k/r (2) where k is a generic constant, and, from (1): t=(v th c)/kr (3)
AN1147 - applicat ion note 4/22 in figure 4, on a time-voltage diagram, are drawn the ideal shapes of the voltage across the capacitor for different resistance values. in particular, we notice that at the minimum value of resistance r min corresponds the minimum time t 1 ; similarly at the maximum resistance r max corresponds the biggest charge time t 2 . for values of resistance laying in the range [r min ,r max ] the voltage is represented by the straight line related to a generic r x corresponding to a time interval t x included between the extremes t 1 and t 2 . fig. 4 - voltages across the capacitor in the charging interval at constant current 4. link between the st52x301 micro and the mirror current as said before, the charging phase of the capacitor is at constant current and this is obtained through an external mirror current circuit. in figure 5 the connections between the micro and the mirror current are shown. fig. 5 - mirror current driven by st52x301 micro
high resolution digital conversion of an ntc by st52x301 5/22 the mirror current is supplied with the highly-stable bandgap voltage reference provided by our micro. to ensure an optimal performance of the circuit, it should be better to use matched transistor with the same electrical and thermal characteristics. from the figure, we can note that the key components of our measurement system, the resistor and the capacitor, are connected to the collectors of transistors, and the voltage across the capacitor is detected by pin 0 of parallel port. now, let us analyse the functionment of pin 0 (pin0) that is a bidirectional line. at the beginning of measurement cycle, pin0 is configured as output by the program and set to logical value 0 (analog system ground): in this way the capacitor is fully discharged. after, the pin0 is placed as input pin (high impedance); at the same instant the timer starts counting. the voltage across the capacitor is free to grow linearly up to the threshold voltage v th (constant current charging). the running program loops checking the state of pin0 that, initially, is at logical 0 but switches to logical 1 after few milliseconds depending on the resistance values. when this commutation occurs, the program interrupts the polling cycle and blocks the timer counting. the total time is stored into two registers ( one of which is the timer counter).then, the time offset due to the minimum charge time t 1 has to be subtracted from this 16-bit value giving an 8-bit data representing the result of a/d conversion. 5. measure resolution we have to determine an adequate number of bits necessary to represent our measure, once the maximum range of variation of the resistance has been fixed. it is obvious that a major number of bits implies a greater resolution and, therefore, precision of measurement. in this application note we will impose a word length so that the resolution is at least 50 w /lsb (i.e. a variation in the less significant bit implies at the most, a resistance variation of 50 w ). it is known that: r min =1k w and r max = 10k w then d r = 9000 w if we use an 8-bit representation, we will have: d r=9000 w /2 8 @ 35 w /lsb with the above considerations we have enough information to set the timer configuration and to implement the structure of the measurement algorithm. referring to figure 4, t 1 represents the smallest time interval when the trimmer has its minimum resistance value (1k w ); in these conditions our 8-bit word has to be equal to 0; in the same way, for the greater time interval t 2 , the word value has to be 255. from practical measurement, we have obtained the following values (with a 33 m f capacitor): tms 1 107 = and tms 2 166 = then, the effective time interval that must be measured will be: d t=(t 2 -t 1 ) = 59ms and, using an 8-bit length, we get the smallest appreciable time interval: d t= d t / 256 = 230 m s
AN1147 - applicat ion note 6/22 with this value we set the prescaler register as we saw in previous paragraphs; instead, with our resolution, the timer counter will be set at 255. summarizing, the 8-bit value will represent the measure proportional to the time interval that in figure 4 we have indicated with d t x . 6. serial communication interfacing the micro st52x301 contains a serial communication interface (sci) that provides a general purpose shift register peripheral, allowing to link several widely distributed mcus, through their sci subsystem (pcs too). the sci gives a serial interface providing communication with common baud rates, up to 38400 hz, and flexible character format. for more information on sci refer to st52x301 data sheet. in figure 6 is provided an interface circuit for serial data transmission from st52x301 and a pc (through one its com: port). fig. 6 - schematic of rs232 interface in our application, for each measurement cycle, the software will transmit the byte containing the evaluated measure. this allows real time processing on evaluated measures or post-processing if you decide to store the information in a media. in figure 7 is shown the dialog box from fuzzystudio tm 3.0 for sci configuration with the settings used in our application.
high resolution digital conversion of an ntc by st52x301 7/22 fig.7 - sci configuration
AN1147 - applicat ion note 8/22 7. software description the software running on the micro can be divided into three blocks: - main program - acquisition phase - data transmission via serial port 7.1 main program the structure of the main program is shown in the figure below: fig. 8 - the main program let us analyze each block: set interrupt: sets the interrupt priorities. init: sets to zero the two bytes containing the upper and lower part of acquisition performed during the acquisition phase. delay_1ms: a delay cycle between a conversion and the next one. acquisition: routine that computes the time interval measure related to resistance value. for more details refer to the acquisition phase block. tx_to_pc : block in which the data is sent output via serial port pin txd. see below for more details.
high resolution digital conversion of an ntc by st52x301 9/22 fig. 9 - the measurement routine 7.2 acquisition phase in figure 9 is shown the block diagram (in fuzzystudio tm 3.0 environment) of ameasuremento routine where the effective detection of measure is performed. before we begin to analyze this routine, we have to explain how to subtract the offset time due to minimum time t1. to do that, let us see what is the digital value corresponding to this time: t min =107 ms offset = t t ms d b min () ( ) === 107 230 465 111010001 storing it in two bytes we have: upper_byte=1 lower_byte=209 then, all we have to do is to start the timer controlling when this 9-bits value is reached; at this point we have to reset and restart the timer to count the right time interval we are interested in (the d t x interval shown in picture 4). d m s
AN1147 - applicat ion note 10/22 let's analyze the flow of the program: set_input: this instruction drives pin0 to be set as input, lets the capacitor start the charging process. start_timer: the timer starts its counting, to discard the offset time t 1 as we discussed before (the 3 subsequent conditional blocks). a condition 7o : waits for the voltage across the capacitor becomes equal to v th =1.9v; when this is true, the state of input pin 0 switches from digital 0 to 1. areceive 0o: then the timer is stopped and the timer counter, containing the measured time, is stores in the variable atargeto. aset-outputo: and res-port: pin0 is set as output at logical level 0 so as to discharge the capacitor towards ground ready for the next acquisition. 7.3 data transmission via serial port after the measurement phase, data are sent to serial port. let us see it in more details (figure 10): n ir_mask1: enables the sci interrupt. n peripherals2: starts the transmission phase by the sci peripheral. n send1: transmits the variable ares_valueo to serial port. n wait1: the program stops execution until the sci interrupt is generated; that indicates the data has been correctly transmitted. fig 10 - the data transmission to serial port
high resolution digital conversion of an ntc by st52x301 11/22 8.1 system power supply mainly, this part of circuitry is made up from the device vb4085 that allows to have a high-stable regulated output voltage equals to 5v with maximum current up to 80 ma. further, the dc ouput voltage is filtered by a low-pass filter. with this voltage the digital and analog circuitry of the micro are supplied. figure 12 shows the power supply circuit used in our application together a brief description of vb4085 features. fig. 11 - the operation scheme of application fig. 12 - power supply section and vb4085 device features 8. hardware description the figure 11 shows the interconnection scheme of all hardware blocks required to implement the application described in the previous paragraphs. it follows that the system hardware can be divided into three main blocks: - system power supply - st52x301 - mirror current
AN1147 - applicat ion note 12/22 8.2 microcontroller st52x301 all main pin connections of the micro are shown. furthermore, we notice the reset circuit required to begin a new cycle measurement, the 5mhz local oscillator and the connection of the data port pin 0 to the mirror current. the pin txd is connected to a teeth-connector for an easy access from outside. 8.3 mirror current this circuital solution has just been widely described in details above. in figure 13 the schematic of whole application is illustrated. a particular care must be taken by filtering the analog and digital power supplies. this is performed connecting some little filtering capacitors (about 0.1 m f) between each vcc and ground vss (refers to st52x301 datasheet). fig. 13 - general schematic of application (without filtering capacitors)
high resolution digital conversion of an ntc by st52x301 13/22 9. an alternative solution the mirror current external circuitry has to be used for constant current charging of the capacitor. this performs a linear a/d conversion of the resistance to be measured. but, if we prefer not to use external circuitry (i.e. for the constraint of transistors matching, or to have a more low-cost application), another solution can be taken into account. instead of using a constant current charging process, we can supply the capacitor with a constant voltage (the dc power supply) from an output pin of the parallel port set to digital value `1'. let us see the basic analytical principle and how this works. during the charge transient, the voltage across a capacitor in a rc-network supplied with a step signal is given from the well-known formula: vt v e c cc trc () / =- - 1 if, during the charge transient, the threshold voltage v th ( v cc ) is reached after a time of t x seconds we have: vvt v e th c x cc tx rc ==- - () ( ) / 1 then, it follows: trc vvkcr xthcc =- - = ln( / ) 1 where k is a constant depending on dc power supply and the device characteristics. then, a linear relation exists between the time needed to reach the threshold and the resistor r. if we choose a capacitor in such a way that the measurement phase is performed at the beginning of the charge process (in the quasi-linear piece of exponential waveform) then the instant when the threshold is reached will be well-defined (nearly as the mirror current case). moreover, with the new solution this is easier to reach because now we are feeding the capacitor with a voltage of 5 v, that is, twice the voltage used in the former case. 9.1 the implementation of a/d conversion in figure 14 we see the modified circuit driving the variable resistor component for a/d conversion. fig. 14 - a/d conversion block diagram
AN1147 - applicat ion note 14/22 in figure 15 there is the timing diagram showing how the first three pins of parallel port (p0, p1, p2) have to be driven by the software to perform the whole phase of measurement. 9.1.1 pre-processing phase ( [0,t 1 ]): first of all, we have to find the offset (refer to block `init' in software description). then, we have to determine the time corresponding to the minimum value of the resistance (in our example 1k w ). for this purpose we charge the capacitor through the resistor r min rising up the pin p2 of the micro. the time needed to reach the threshold voltage is the wanted offset value. 9.1.2 measurement phases ( [t 2 ,t 3 ], [t 4 ,t 5 ]): normally, in the measurement phase p2 is not used (configured as input/high impedance). for charging the capacitor through the ntc we have to put p0 at logical 1 while starting the timer. after the voltage has reached the threshold (software polling the pin p1), we stop the timer, storing its register counter value and, at the same time, configuring p0 as input and p1 as output at zero ground (logical 0) allowing fast discharge of the capacitor towards ground. so, the next measurement phase runs again, after being sure that the capacitor has completely discharged. fig. 15 - timing diagram
high resolution digital conversion of an ntc by st52x301 15/22 10. determining the resistance value of an ntc sensor let us see an immediate application of the method previously described. we want to convert the value of a 10k w ntc working in the range temperature of 8 , 28 c using an 8-bit resolution. if the characteristic of the ntc is not-linear we can linearize it putting a 10k w resistor in parallel with the sensor. experimental measures of the charging times at the minimum and maximum temperatures give for the resistance the following values: (*) with a 4.7 m f capacitor then to convert the range of temperature [8 28 c] in a digital data in the [0 , 255] range we have to deal with the following intervals: d t( c) =t max -t min =20 c d t(ms) = t max -t min = 5.08ms with this data we find the value to be loaded in the prescaler of the timer: d t =d t / 256=19.84 m s we note that with an 8-bit resolution and supposing linear the ntc characteristic, the maximum sensitivity for temperature is: d t =d t / 256= 0.08 c / lsb that is a suitable value in the most common general purpose applications. r ntc (k ) time (ms) (*) t( c) 8 7.2 10.36 28 4.8 15.44 w
AN1147 - applicat ion note 16/22
high resolution digital conversion of an ntc by st52x301 17/22 appendix: st52x301 assembler code in this appendix is shown the source program written in assembler language. it refers to the mirror current solution (refer to chapter 8) and it originates directly from the assembler generated with fuzzystudio tm 3.0 tool. ; compile time: wed jul 14 15:02:13 1999 ; device type: st52x301 ; compiler version: 01.02 (06.11.98) irq 3 timer_interrupt irq 4 triac_interrupt irq 1 ad_interrupt irq 2 sci_interrupt irq 0 external_interrupt stop @@wclstart@@: ldcf 0 0 ldcf 1 8 ldcf 2 2 ldcf 3 128 ldcf 4 125 ldcf 5 4 ldcf 6 40 ldcf 7 12 ldcf 8 0 ldcf 9 0 ldcf 10 40 ldcf 11 128 ldcf 12 66 ldcf 13 88 ldcf 14 0 ldcf 15 228 start: set_interrupt: ir_priority1: ldcf 15 198 ir_mask4: ldcf 14 4 return7: @@00000: init: ldrc 13 0 ldrc 15 0
AN1147 - applicat ion note 18/22 delay_1ms: @@00001: acquisition: ir_mask0: ldcf 14 8 arth3: ldrc 12 0 ldrc 11 0 ldrc 15 0 send255: mdgi ldrc 0 255 ldpr 0 0 megi set_input: ldcf 0 0 start_timer: ldcf 6 41 ldcf 6 43 condition2: mdgi ldrc 0 1 ldri 1 6 and 0 1 megi jpnz @@00004 jp @@00003 @@00004: jp reset_timer1 jp @@00005 @@00003: jp condition0 @@00005: reset_timer1: ldcf 6 40 condition4: mdgi ldrc 0 1 sub 0 12 megi pnz @@00006
high resolution digital conversion of an ntc by st52x301 19/22 @@00007: jp set_output jp @@00008 @@00006: jp arth4 @@00008: set_output: ldcf 0 1 res_port: mdgi ldrc 0 0 ldpr 2 0 megi return4: jp @@00002 condition0: mdgi ldrc 0 2 sub 0 15 megi jpnz @@00009 @@00010: jp receive1 jp @@00011 @@00009: jp condition2 @@00011: receive1: ldri 13 4 condition1: mdgi ldrc 0 209 sub 0 13 megi pnz @@00012 @@00013: jp reset_timer jp @@00014 @@00012: jp condition2 @@00014: reset_timer: ldcf 6 40
AN1147 - applicat ion note 20/22 resend255: mdgi ldrc 0 255 ldpr 0 0 megi restart_timer: ldcf 6 41 ldcf 6 43 arth2: ldrc 12 1 ldrc 15 0 condition7: mdgi ldrc 0 1 ldri 1 6 and 0 1 megi jpnz @@00016 jp @@00015 @@00016: jp receive0 jp @@00017 @@00015: jp condition7 @@00017: arth4: ldrc 11 0 jp set_output receive0: ldri 11 4 jp reset_timer1 @@00002: tx_to_pc: ir_mask1: ldcf 14 4 peripherals2: ldcf 3 129 send1: stx 11 wait1: waiti peripherals3: ldcf 3 128
high resolution digital conversion of an ntc by st52x301 21/22 return0: @@00018: jp delay_1ms external_interrupt: iret1: reti ad_interrupt: iret4: reti sci_interrupt: iret2: reti timer_interrupt: arth0: mdgi ldrc 0 1 add 15 0 megi iret0: reti triac_interrupt: iret3: reti stop
AN1147 - applicat ion note 22/22 information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specification mentioned in this publication are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of stmicroelectronics. the st logo is a trademark of stmicroelectronics ? 1999 stmicroelectronics printed in italy all rights reserved fuzzystudio tm is a registered trademark of stmicroelectronics stmicroelectronic group of companies australia - brazil - china - finland - france - germany - hong kong - india - italy - japan - malaysia - malta - morocco - singapore - spain - sweden - switzerland - united kingdom - u.s.a. http://www.st.com


▲Up To Search▲   

 
Price & Availability of AN1147

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X